package com.jp.knowledge.my.activity;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.comm.SlidingActivity;
import com.jp.knowledge.my.business.Vector;
import com.jp.knowledge.my.util.MyUtil;

import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

/**
 * @author gzejia 978862664@qq.com
 */
public class QrCodeActivity extends SlidingActivity {

    /**
     * 个人二维码
     */
    public static final int QR_CODE_PERSONAL = 0;
    /**
     * 组织二维码
     */
    public static final int QR_CODE_ORGANIZE = 1;

    private int mQrScanType = QR_CODE_PERSONAL;

    @ViewInject(R.id.qr_tv_organize)
    private TextView mOrganizeTv;

    @ViewInject(R.id.qr_tv_hind)
    private TextView mHindTv;

    @ViewInject(R.id.qr_iv_image)
    private ImageView mQrScanIv;

    @Override
    protected int getResourceId() {
        return R.layout.activity_qr_code;
    }

    @Override
    protected void init() {
        initOthers();
        initTitle();
    }

    @Event(value = {R.id.icon_left, R.id.qr_btn_send, R.id.qr_btn_share},
            type = View.OnClickListener.class)
    private void onClick(View view) {
        switch (view.getId()) {
            case R.id.icon_left:// 返回
                finish();
                break;
            case R.id.qr_btn_send:// 转发

                break;
            case R.id.qr_btn_share:// 分享到微信

                break;
        }
    }

    private void initTitle() {
        topName.setText(mQrScanType == QR_CODE_PERSONAL ?// 个人二维码
                R.string.qr_tv_title_personal : R.string.qr_tv_title_organize);
        topDesc.setVisibility(View.GONE);
        leftIcon.setImageResource(R.mipmap.arrow_white_left);
        rightIcon.setVisibility(View.GONE);
    }

    private void initOthers() {
        mQrScanType = getIntent().getIntExtra(
                Vector.TRANSFER_INTEGER + "qr_scan_type", QR_CODE_PERSONAL);

        if (mQrScanType == QR_CODE_PERSONAL) {
            mHindTv.setText(R.string.qr_tv_hind_personal);
            mOrganizeTv.setText("巫老板");
        } else {
            String organizeStr = getResources().getString(R.string.qr_tv_hind_organize);
            mHindTv.setText(MyUtil.changeTextColor(organizeStr, getResources().getColor(R.color.theme_color),
                    organizeStr.indexOf("码"), organizeStr.indexOf("）")));
            mOrganizeTv.setText("创将科技");
        }
        x.image().bind(mQrScanIv, "https://sp0.baidu.com/5aU_bSa9KgQFm2e88IuM_a/micxp1.duapp.com/qr.php?value=%E5%88%9B%E5%B0%86%E7%A7%91%E6%8A%80",
                Vector.IMAGE_GENERAL);
    }
}
